<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Random;
use think\Config;
use think\Validate;
use think\Db;
use app\admin\model\Admin;
use fast\Http;

/**
 * 会员接口
 */
class Device extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();


    }


    public function listWithPointAndFeatures()
    {
        $adminuser = Db::name('user_third')->where(['mobile'=>$this->auth->username])->find();
        $url = config('device_domain').'/api/nx-iot/device/listWithPointAndFeatures';
        $param = json_encode(['enable'=>'active','index'=>1,'onlyReadFeatures'=>true,'onlyWriteFeatures'=>false,'parentId'=>0,'size'=>0]);
        $header = array('Content-Type: application/json; charset=utf-8',
            'Content-Length:' . strlen($param),'Authorization:'.$adminuser['token_type'].' '.$adminuser['access_token']);
        $res = Http::post($url,$param,[],$header);
        return $res;
    }


    public function calculateList()
    {
        $adminuser = Db::name('user_third')->where(['mobile'=>$this->auth->username])->find();
        $url = config('device_domain').'/api/nx-iot/point/calculate/list';
        $param = json_encode(['index'=>1,'parentId'=>0,'size'=>0]);
        $header = array('Content-Type: application/json; charset=utf-8',
            'Content-Length:' . strlen($param),'Authorization:'.$adminuser['token_type'].' '.$adminuser['access_token']);
        $res = Http::post($url,$param,[],$header);
        return $res;
    }


    public function scanList()
    {
        $adminuser = Db::name('user_third')->where(['mobile'=>$this->auth->username])->find();
        $url = config('device_domain').'/api/nx-iot/point/scan/list';
        $param = json_encode(['index'=>1,'parentId'=>0,'size'=>0]);
        $header = array('Content-Type: application/json; charset=utf-8',
            'Content-Length:' . strlen($param),'Authorization:'.$adminuser['token_type'].' '.$adminuser['access_token']);
        $res = Http::post($url,$param,[],$header);
        return $res;
    }


    public function pointList()
    {
        $params = $this->request->post();
        $adminuser = Db::name('user_third')->where(['mobile'=>$this->auth->username])->find();
        $url = config('device_domain').'/api/nx-iot/point/list';
        $param = json_encode($params);
        $header = array('Content-Type: application/json; charset=utf-8',
            'Content-Length:' . strlen($param),'Authorization:'.$adminuser['token_type'].' '.$adminuser['access_token']);
        $res = Http::post($url,$param,[],$header);
        return $res;
    }
}
